/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JF_SeleccionarMedico.java
 *
 * Created on 30-jun-2010, 1:57:39
 */

package cliente.presentacion.administrador.beneficiarios;

import cliente.negocio.Controlador_Gestion_Beneficiario;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import server.dominio.Medico;

/**
 *
 * @author tpaxle
 */
public class JF_SeleccionarMedico extends javax.swing.JFrame implements iJF_SeleccionarMedico {

    /** Creates new form JF_SeleccionarMedico */
    public JF_SeleccionarMedico() {
        initComponents();
        this.setVisible(true);
    }

    public JF_SeleccionarMedico(iControlador_SeleccionMedico C_Admin, List<Medico> listamedicos, int filtro) {
        initComponents();
        this.setLocation((int)Toolkit.getDefaultToolkit().getScreenSize().getWidth()/4,(int)Toolkit.getDefaultToolkit().getScreenSize().getHeight()/6);
        this.setVisible(true);
        this.C_Admin = C_Admin;
        this.listamedicos = listamedicos;
        this.tipo_filtro = filtro;
        jComboBox1.setSelectedIndex(tipo_filtro-1);
        listamedicos_filtro = new ArrayList<Medico>();
        iniciartabla();

    }



    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton_seleccionar = new javax.swing.JButton();
        jButton_Cancelar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setAlwaysOnTop(true);
        setResizable(false);

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/imagen_corporativa2.png"))); // NOI18N
        jLabel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "NIF", "Nombre", "Apellidos", "Especialidad", "Domicilio", "Telefono Fijo", "Telefono Movil"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jButton_seleccionar.setText("Seleccionar");
        jButton_seleccionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_seleccionarActionPerformed(evt);
            }
        });

        jButton_Cancelar.setText("Cancelar");
        jButton_Cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton_CancelarActionPerformed(evt);
            }
        });

        jLabel1.setText("filtro");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Cabecera", "Pediatría", "Urología", "Cirugía", "Neurología", "Ginecología", "Digestivo", "Oftalmología", "Ninguno" }));
        jComboBox1.setSelectedIndex(8);
        jComboBox1.setEnabled(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 809, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jButton_Cancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(jButton_seleccionar, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 809, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton_Cancelar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton_seleccionar, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_CancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_CancelarActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton_CancelarActionPerformed

    private void jButton_seleccionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_seleccionarActionPerformed
        if(jTable1.getSelectedRow()==-1){
            this.error(1);
        }else{
            C_Admin.seleccionarMedico(listamedicos_filtro.get(jTable1.convertRowIndexToModel(jTable1.getSelectedRow())));
            dispose();
        }
    }//GEN-LAST:event_jButton_seleccionarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_Cancelar;
    private javax.swing.JButton jButton_seleccionar;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

    private iControlador_SeleccionMedico C_Admin;
    private int tipo_filtro= 0;
    private List<Medico> listamedicos;
    private List<Medico> listamedicos_filtro;
    private String [] tiposmedicos= {"Cabecera", "Pediatría", "Urología", "Cirugía", "Neurología", "Ginecología", "Digestivo", "Oftalmología"};

    private void error(int nerror) {
        switch(nerror){
            case 1:
                JOptionPane.showMessageDialog(null, "No ha seleccionado ningún medico", "Aviso Medicos", JOptionPane.WARNING_MESSAGE);
                break;
        }
    }

      private void iniciartabla() {
        DefaultTableModel modelo= (DefaultTableModel) jTable1.getModel();
        modelo.setNumRows(0);
        for (Medico medico: listamedicos){
            if(medico.getIdTipoMedico()== tipo_filtro){
                listamedicos_filtro.add(medico);
                Object [] datos= {medico.getUsuario().getNif(), medico.getUsuario().getNombre(), medico.getUsuario().getApellidos(), tiposmedicos[medico.getIdTipoMedico()-1], medico.getUsuario().getDomicilio() , medico.getUsuario().getTelFijo() , medico.getUsuario().getTelMovil()};
                modelo.addRow(datos);
            }
        }
    }
}
